<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
      * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .header {
            height: 160px;
            background: darkseagreen;
        }

        .menu {
            height: 90px;
            background-color: grey;
        }

        .tabBox>.content {
            height: 500px;
            text-align: center;
            line-height: 500px;
            border: 1px solid #000;
        }

        .footer {
            height: 500px;
            background-color: #000;
        }

        .slideMenu {
            position: fixed;
            right: 30px;
            top: 50%;
            transform: translateY(-50%);
            padding: 5px;
            border-radius: 3px;
            background: cornsilk;
        }

        .slideMenu li {
            line-height: 30px;
            margin: 10px;
            border: 1px solid #000;
            padding: 5px;
        }

        .slideMenu .active {
            background: #6ff;
            color: #fff;
        }
    </style>
</head>
<body>
        <div class="header">
        </div>
            <div class="menu">    
            </div>
            <div class="tabBox">
                <div class="content">01</div>
                <div class="content">02</div>
                <div class="content">03</div>
                <div class="content">04</div>
                <div class="content">05</div>
                <div class="content">06</div>
                <div class="content">07</div>
                <div class="content">08</div>
                <div class="content">09</div>
                <div class="content">10</div>
            </div>
            <div class="footer"></div>
        
            <ul class="slideMenu">
                <li class="active">tab01</li>
                <li>tab02</li>
                <li>tab03</li>
                <li>tab04</li>
                <li>tab05</li>
                <li>tab06</li>
                <li>tab07</li>
                <li>tab08</li>
                <li>tab09</li>
                <li>tab10</li>
            </ul>
            <script>
                // 导航跳动
            var contentlist=document.getElementsByClassName("content");
            var footerA=document.getElementsByClassName("footer")[0]
            var tablist=document.getElementsByTagName("li")
            window.onscroll=function(){
               var scrolltop=document.documentElement.scrollTop||document.body.scrollTop
               for(var i=0;i<contentlist.length;i++){
                    var start=contentlist[i].offsetTop
                    if(i==contentlist.length-1){
                        var end=footerA.offsetTop
                    }
                    else{
                        var end=contentlist[i+1].offsetTop
                    }
                    console.log(scrolltop,start,end)
                    if(scrolltop+200>start&&scrolltop+200<end){
                        for(var j=0;j<tablist.length;j++){
                          tablist[j].className=""
                        }
                        tablist[i].className="active"
                    }
               }  
            } 

            // 点击鼠标滑动
            var time
            for(let i=0;i<tablist.length;i++){
               tablist[i].onclick=function(){
                   clearInterval(time)
                 var end=contentlist[i].offsetTop
                 var start=document.documentElement.scrollTop||document.body.scrollTop
                 time=setInterval(fn,100)
                 function fn(){
                     var start=document.documentElement.scrollTop||document.body.scrollTop                    
                     if(end>start){
                         if(start>=end){
                             clearInterval(time)
                         }
                     }
                     else{
                         if(start<end){
                             clearInterval(time)
                         }
                     }
                       start += (end-start)/10
                       document.documentElement.scrollTop=start
                 }                  
               }
            }
            </script>
</body>
</html>